package net.maku.kyy.utils;

import cn.hutool.core.lang.UUID;
import net.maku.framework.common.constant.Constant;
import net.maku.framework.common.constant.MessageConstant;
import net.maku.framework.common.exception.ServerException;
import net.maku.framework.security.utils.ThreadLocalUtil;
import org.springframework.stereotype.Component;

import java.util.Map;
@Component
public class GetUserMessageUtil {

    public static Long getUserId() {
        Map map= ThreadLocalUtil.get();
        if (map==null){
            throw new ServerException(MessageConstant.PLEASE_LOGIN);
        }
        Long userId = (Long) map.get(Constant.KYY_USER_ID);
        if (userId==null){
            throw new ServerException(MessageConstant.PLEASE_LOGIN);
        }
        return userId;
    }


    public static String RandomAccount() {
        return UUID.randomUUID().toString().replace("-", "").substring(0, 10);
    }
}
